

*** This do file generates figure B8 for the minimum wage precommitment paper.

*** Stacked event studies using the year of first statutory increase as the first treatment year analyzing large and small statutory increasers separately
*** Prime age individuals
* If needed change global path to point to directory where files are stored on your computer
*global path "I:/DataSets5/Duncan/Dropbox/Recent Minimum Wage Changes/2020.12 NBER Update/JOLE Precommittment Replication"
global dtadir "$path/Data"
global tabdir "$path/Tables"
global figdir "$path/Figures"
global estdir "$path/Estimates"
global logdir "$path/Logfiles"

*****************************************************************************************************
************		                     2. Program for Stacked Dataset		************
*****************************************************************************************************

capture program drop gen_dataset 
program define gen_dataset 

	** syntax
	syntax, treatyear(varname) cohort(real)

	use "${path}\Data\ACSEventStudiesData.dta", clear
	
	keep if `treatyear' == `cohort' | `treatyear' ==.
	gen treat_stacked = 0
	replace treat_stacked = 1 if `treatyear' !=. /* treatment var is any cohort year */
	gen cohort = `cohort'  /* label reform */ 

	** recode years to be in event time 
	qui gen t = year - `cohort' + 1
	qui replace t = -3 if inrange(t,-10,-3) 
	qui replace t = 4 if inrange(t,4,10) 
	
	* Generate sample indicators
	gen lowskilled = 0
	replace lowskilled = 1 if inrange(age,16,25) & dropout == 1

	gen young = 0
	replace young = 1 if inrange(age,16,21)

	gen primeage = 0
	replace primeage = 1 if inrange(age,26,54)

	gen highskill = 0
	replace highskill = 1 if inrange(age,26,54) & educ > 6 
	
end

*****************************************************************************************************
************		                     3. Program for Event Studies				     ************
*****************************************************************************************************


capture program drop did_stacked
program define did_stacked

	*------------------------ 3.1 Syntax --------------------------

	syntax varlist(min=2 max=2), [xvar(string) pretrend(real 0) otherlab(string) panel(string)]

	local outcome `1'
	local sample = subinstr("`2'",",","",.)
	
	*------------------------ 3.2 Set Up --------------------------

	est clear
	
	* event time defintion and range
	cap drop tvar
	gen tvar = t + 4

	* generate sample tag
	cap drop sample
	gen sample = inrange(tvar, 1, 8) & `sample' == 1
	keep if sample == 1
	local ref = 0 + 4

	*------------------------ 3.3 Event Study --------------------------
	
	* Set controls
	if "`otherlab'" == "nocontrols" {
	    local xvar
		local controlslabel `"No Controls"'
	}
	
	else if "`otherlab'" == "basecontrols" {
	    local xvar lnPersonalIncome HPI
		local controlslabel `"Sparse Controls"'
	}
	
	else if "`otherlab'" == "richcontrols" {
	    local xvar i.age i.educ lnPersonalIncome HPI D3lnPersonalIncome D3HPI
		local controlslabel `"Rich Controls"'
	}
	
	else {
	    local xvar
		local controlslabel `"None"'
	}
	
	* Set sample label
	if "`sample'" == "lowskilled" {
		local samplabel  `"Low-Skilled"'
	}
	
	else if "`sample'" == "young" {
		local samplabel `"Young"'
	}
	
	else if "`sample'"== "primeage" {
		local samplabel `"Prime Age"'
	}
	else if "`sample'" == "highskill" {
		local samplabel `"Prime Age Higher-Skilled"'
	}
	else {
		local samplabel `"None"'
	}
	
	* Stacked Event Study Regression Large Increaser Treated Group (Need to drop both small statutory increasers anmd indexers)
	eststo: reghdfe `outcome' b`ref'.tvar##i.treat_stacked `xvar' [pw=cmpwgt] if sample == 1 & indexer == 0 & StatIncreaserSmall == 0, absorb(statefip year cohort##statefip) cluster(statefip)
	
	* Save coefficients
		* create matrix
		mat est = J( 8 , 8, .)
						
		* fill matrix with values of t, point estimates, and CI
		local n = 1
		foreach t of numlist -3/4 {
			* tnorm
			local tnorm = `t' + 4
			* event time
			mat est[`n',1]  = `t' - 0.1
			* normalized coefficient
			mat est[`n',2] =  _b[`tnorm'.tvar#1.treat_stacked]
			* lower CI
			mat est[`n',3] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.025)*_se[`tnorm'.tvar#1.treat_stacked]
			* upper CI
			mat est[`n',4] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.975)*_se[`tnorm'.tvar#1.treat_stacked]
			local n = `n' + 1
		}
		
	* Stacked Event Study Regression Small Increaser Treated Group (Need to drop large statutory increasers). Make sure Maine is Not includded here even though it is a "no change" state since it is included in the large increaser set
	eststo: reghdfe `outcome' b`ref'.tvar##i.treat_stacked `xvar' [pw=cmpwgt] if sample == 1 & StatIncreaserLarge == 0 & statefip != 23, absorb(statefip year cohort##statefip) cluster(statefip)

		* fill matrix with values of t, point estimates, and CI
		local n = 1
		foreach t of numlist -3/4 {
			* tnorm
			local tnorm = `t' + 4
			* event time
			mat est[`n',5]  = `t' + 0.1
			* normalized coefficient
			mat est[`n',6] =  _b[`tnorm'.tvar#1.treat_stacked]
			* lower CI
			mat est[`n',7] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.025)*_se[`tnorm'.tvar#1.treat_stacked]
			* upper CI
			mat est[`n',8] = _b[`tnorm'.tvar#1.treat_stacked] + invnorm(0.975)*_se[`tnorm'.tvar#1.treat_stacked]
			local n = `n' + 1
		}
	
		* store coefficients to dataset
		cap drop est?
		svmat est
		
	*------------------------ 3.4 Plot  --------------------------


	graph twoway (scatter est2 est1, msymbol(circle) msize(medium) mc(black) lc(black)) ///
				(rspike est3 est4 est1, color(black) m(i)) ///
				(scatter est6 est5, msymbol(triangle) msize(medium) mc(black) lc(black)) ///
				(rspike est7 est8 est5, color(black) m(i) ///
					yline(0, lcolor(black)) ///
					ylabel(-.075 "-.075" -.05 "-.050" -.025 "-.025" 0 "0" .025 ".025", labsize(small) gmin gmax) ///
					xlabel(-3 "-3+" -2 "-2" -1 "-1" 0 "0" 1 "1" 2 "2" 3 "3" 4 "4+", labsize(small)) xscale(range(-3 4)) ///
					xtitle("") ytitle("") bgcolor(white) graphregion(color(white)) ///
					title("Panel `panel': `samplabel' with `controlslabel'", size(medsmall) color(black)) ///
					legend(order(1 "Large Increasers" 3 "Small Increasers") rows(1) region(lstyle(none)) size(small) symxsize(small) symysize(small)) ///
					name("`outcome'_`sample'_`otherlab'", replace)) 
					*graph save "$figdir/`outcome'_`sample'_`otherlab'_small_large.pdf", as(pdf) replace

end

*****************************************************************************************************
************				          4. Graph			        *************
*****************************************************************************************************
#delimit cr

cap log close 

* start log file 
log using "$logdir/stacked-event-studies-policy-categories-prime-age-drop-indexers.log", replace

* Load data
use "${path}/Data/ACSEventStudiesData.dta", clear

tab statefip legimpyear1


* -------------------------- 2.1 Create Event Study Dataset for Increase --------------------------- 

tempfile stacked

* 2013
	gen_dataset, treatyear(legimpyear1) cohort(2013)
	qui save `stacked', replace
* 2014
	gen_dataset, treatyear(legimpyear1) cohort(2014)
	qui append using `stacked'
	qui save `stacked', replace 
* 2015
	gen_dataset, treatyear(legimpyear1) cohort(2015)
	qui append using `stacked'
	qui save `stacked', replace
* 2016
	gen_dataset, treatyear(legimpyear1) cohort(2016)
	qui append using `stacked'
	qui save `stacked', replace 
 * 2017
	gen_dataset, treatyear(legimpyear1) cohort(2017)
	qui append using `stacked'
	qui save `stacked', replace 
* 2019
	gen_dataset,  treatyear(legimpyear1) cohort(2019)
	qui append using `stacked'
	qui save `stacked', replace

* Drop all states that were originally indexers
drop if indexer == 1

* -------------------------- 2.2 Graph --------------------------- 

* primeage
	did_stacked employed primeage, otherlab(nocontrols) panel(A)
	did_stacked employed primeage, otherlab(basecontrols) panel(B)
	did_stacked employed primeage, otherlab(richcontrols) panel(C)
	


* Combined employment graph prime-age and prime-age high-skilled
grc1leg2 employed_primeage_nocontrols employed_primeage_basecontrols employed_primeage_richcontrols, ///
	l1("Change", size(medsmall)) b1("Event Time", size(medsmall)) ring(2) xsize(20) ysize(11) margins(tiny) ///
	legendfrom(employed_primeage_basecontrols) lsize(medsmall) graphregion(color(white)) rows(2)
graph save "$figdir/stacked-event-studies-primeage-policy-categories-drop-all-indexers.gph", replace
graph export "$figdir/stacked-event-studies-primeage-policy-categories-drop-all-indexers.pdf", as(pdf) replace


* 	employed_highskill_nocontrols employed_highskill_basecontrols employed_highskill_richcontrols, ///

